import java.util.Arrays;
import java.util.Scanner;

interface IntegerStack {
	public Integer push(Integer item);


	public Integer pop();

	public Integer peek(); 

	public boolean empty(); 

	public int size(); 
}

class ArrayIntegerStack implements IntegerStack {
	Integer arr[];
	private int top;

	public ArrayIntegerStack(int n) {
		this.arr = new Integer[n];
		top = 0 ;
	}
	public Integer push(Integer item) {
		if (item == null)
			return null;
		if (top == arr.length)
			return null;
		arr[top++] = item;
		return item;
	}

	public Integer pop() {
		if (top == 0)
			return null;
		return arr[--top];
	}

	public Integer peek() {
		if (top == 0)
			return null;
		return arr[top-1];
	}

	public boolean empty() {
		if (top == 0)
			return true;
		return false;
	}

	public int size() {
		return top ;
	}
}

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt() ;
		ArrayIntegerStack arr = new ArrayIntegerStack(n);
		int m = sc.nextInt();
		for (int i = 0; i < m; i++) {
			System.out.println(arr.push(sc.nextInt()));
		}
		System.out.println(arr.peek() + "," + arr.empty() + "," + arr.size());
		System.out.println(Arrays.toString(arr.arr));
		int x = sc.nextInt();
		for (int i = 0; i < x; i++) {
			System.out.println(arr.pop());
		}
		System.out.println(arr.peek() + "," + arr.empty() + "," + arr.size());
		System.out.println(Arrays.toString(arr.arr));
	}
}